<template>
    <!-- 修改对话框 -->
    <el-dialog title="修改运营方" :visible.sync="dialogVisible" width="600px">
        <div style="max-height: 400px; overflow-y: auto;">
            <div style="overflow: auto; max-height: 600px;">
                <!-- 表单内容 -->
                <el-form ref="form" :model="form" label-width="120px" size="small">
                    <el-form-item label="运营方名称" prop="name"
                                  :rules="[{ required: true, message: '运营方名称不能为空', trigger: 'blur' },]">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="是否试用" prop="isTry">
                        <el-radio v-model="form.isTry" label="0">是</el-radio>
                        <el-radio v-model="form.isTry" label="1">否</el-radio>
                    </el-form-item>
                    <el-form-item label="过期时间" prop="expireTime">
                        <el-date-picker
                            v-model="form.expireTime"
                            type="date"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            size="small"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            :clearable="true"
                            :style="{width:'100%'}"
                        ></el-date-picker>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
              <el-button @click="cancel" size="small">取 消</el-button>
              <el-button type="primary" @click="clickToChangePermit" size="small">确 定</el-button>
            </span>
        </div>

    </el-dialog>
</template>

<script>
import {addTenant} from "@/admin/api/admin/operator/operator"

export default {
    data() {
        return {
            dialogVisible: false,
            id: 0,
            form: {
                name: "",
                isTry: "",
                expireTime: ""
            },
            checkedNodes: [],
        };
    },
    methods: {
        cancel() {
            this.dialogVisible = false;
        },
        showDialog(e, row) {
            this.form = row
            if (typeof this.form.isTry === 'number') {
                this.form.isTry = JSON.stringify(this.form.isTry);
            }
            this.form.expireTime = this.$formatDateTime(this.form.expireTime)

            this.dialogVisible = !this.dialogVisible;
        },
        clickToChangePermit() {
            if (this.$refs.form) {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        addTenant(this.form, this.form.id).then((res) => {
                            if (res.code == 200) {
                                this.dialogVisible = false;
                                this.$refs["form"].resetFields();
                                this.$message({
                                    message: res.message,
                                    type: "success",
                                });
                                this.$parent.getOperatorList();
                            } else {
                                this.$message({
                                    message: res.message,
                                    type: "error",
                                });
                            }
                        });
                    } else {
                        // 表单验证失败后的逻辑
                        this.$message.warning('表单验证失败，请检查输入')
                    }
                });
            } else {
                console.error('Form ref not found.');
            }

            this.checkedNodes.forEach(node => {
            });

        },
    },

};
</script>


<style lang="less" scoped>
/deep/ .el-form-item__label {
    width: 120px !important;
}

.dialog-footer {
    margin: 20px 0 0 410px;
}
</style>
